<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%
	String hospitalNotesJson= (String)request.getAttribute("hospitalNotesJson");
	String pageJson= (String)request.getAttribute("pageJson");
 %>


<!--内容部分-->

    
<div class="list_NR">
    <div class="loc">
        <h3>文件上传</h3>
       <!--  <ul class="loc_loc">
          	  病案归档 > 文件上传
        </ul> -->
    </div>
    
    <div class="list_con_table">
        <input type="hidden" value="${medRecordQuery.totalCounts }" id="totalCountsHidden">
		<%-- <form action="${basePath}/medrecord/unPigeonhole" method="get" id="queryForm"> --%>
		<form >
		<input type="hidden" name="currentPage" value="${medRecordQuery.currentPage }" id="currentPageHidden">
    	<input type="hidden" name="pageSize" value="${medRecordQuery.pageSize }" id="pageSizeHidden">
    	<div class="search_table">
           <ul class="clearfix" style="margin-bottom:0;">

            <li class="Label_1" style="width:11%">出院日期：&nbsp;</li>
               <li class="Label_2" style="width:27%;">
                   <input style="width:42%;" class="input_box" id="outHospitalStartTime" name="outHospitalStartDate" value='<fmt:formatDate value="${medRecordQuery.outHospitalStartDate}" pattern="yyyy-MM-dd"/>' onFocus="WdatePicker()" type="text" > 
                   - <input style="width:42%" class="input_box" id="outHospitalEndTime" name="outHospitalEndDate"  value='<fmt:formatDate value="${medRecordQuery.outHospitalEndDate}" pattern="yyyy-MM-dd"/>' onFocus="WdatePicker()" type="text" >
               </li>
               <li class="Label_1" style="width:11%">识别码：&nbsp;</li>
               <li class="Label_2">
               	<input class="input_box" type="text" id="mrId"  name="mrId" value='' />
               </li>
               <li class="Label_1" style="width:11%">患者姓名：&nbsp;</li>
               <li class="Label_2">
               	<input class="input_box" type="text" id="name"  name="name" value='' />
               </li>
               <li class="Label_1" style="width:11%">身份证号：&nbsp;</li>
               <li class="Label_2" style="width:27%;"><input class="input_box" type="text" style="width:94%;"  id="idCard" name="idCard" id='' value='${medRecordQuery.idCard}' />
               	 
               </li>
               
               <li class="Label_1" style="width:11%">出院科室：&nbsp;</li>
               <li class="Label_2" >
               
               	<select class="input_box" id="outHospitalOfficeId" name="outHospitalOfficeId">
               		<option value="">请选择</option>
               		<c:forEach var="office" items="${offices }"> 
               			<option <c:if test="${medRecordQuery.outHospitalOfficeId==office.id}">selected="selected"</c:if> value="${office.id }">${office.name }</option>
               		</c:forEach>
                	
                	</select>
                </li>
                <li class="Label_1" style="width:11%">病案号：&nbsp;</li>
                <li class="Label_2">
                 <input class="input_box" type="text" name="inhospital" value="">
                </li>
                <li class="Label_1" style="width:11%;height:76px;line-height:76px;">离院方式：&nbsp;</li>
                <li class="Label_2" style="width:88%;height:76px;text-align:left;padding-top:10px;">
                	<c:forEach items="${basicInfo['outHospitalTypes']}" var="outHospitalType">
                		<input type="checkbox" class="check_cl" name="outHospitalTypeIds" value="${outHospitalType.id}"><span>${outHospitalType.name}</span>
                		
                	</c:forEach>
                	
                	<input class="btn_qx" type="button" name="" onclick="selectAll()" value="全选">
                	<input class="btn_qx" type="button" name="" onclick="disableAll()" value="取消">
                </li>
                <li class="Label_5">
                    <div class="right">
                    	<a id="Search" onclick="queryQua(1,10)">查询</a>
                    </div>
                </li>
            </ul>
        </div>
     </form>

   </div>

   <table class="Search_tableList"cellpadding="0" cellspacing="0">

       <tr>
           <td class="tdLabel_4">姓名</td>
           <td class="tdLabel_4">身份证号</td>
           <td class="tdLabel_4">识别码</td>
           <td class="tdLabel_4">出院日期</td>
           <td class="tdLabel_4">出院科室</td>
           <td class="tdLabel_4">离院方式</td>
           <!-- <td class="tdLabel_4">状态</td> -->
           <td class="tdLabel_4">操作</td>
       </tr>
       <tr id="loading" style="height:50px;display:none">
	                 <td colspan="6" align="center" ><img src="${basePath}/static/publics/assets/layer/skin/default/loading-2.gif"></td>
	                </tr>
      
       <tbody id="tbody">
       	<%-- <c:forEach var="med" items="${bindList }">
       		<tr>
       			<td class='tdLabel_5'>
       				<div class='imgIcon'><img src='${basePath}/static/publics/images/file.png' alt=''/></div>
       			</td>
       			<td class='tdLabel_5'><fmt:formatDate value="${med.uploadDate}" pattern="yyyy-MM-dd"/></td>
       			<td class='tdLabel_5'>${med.name}</td>
       			<td class='tdLabel_5'>${med.id_number}</td>
       			<td class='tdLabel_5'>${med.treatment_no}</td>
       			<td class='tdLabel_5'><fmt:formatDate value="${med.treatment_date}" pattern="yyyy-MM-dd"/></td>
       			<td class='tdLabel_5'>${med.treatment_type_name}</td>
       			<td class='tdLabel_5'>${med.hospital_name }</td>
       			<td class='tdLabel_5'>${med.comment }</td>
       			<td class='tdLabel_5'>
       				<c:if test="${empty med.first_level_medical_guid }">
       					<a target='_blank' href='${basePath}/bind/pigeonHoleList?id=${med.id}'>绑定</a>
       				</c:if>
       				<c:if test="${not empty med.first_level_medical_guid }">
       					已绑定
       				</c:if>
       			</td>
       		</tr>
       	</c:forEach> --%>
        </tbody>
           
       
    </table>

    <div id="pageList" class="pageList">
        <ul class="pagination clearfix" id="page_plus"></ul>
        <div class="pagination">
            <div>总共：<b id="totalPage">0</b> 条信息    当前页是第 <b id="currentPage">0/0</b>　页</div>
        </div>
    </div>
</div>
<!--script JS部分-->
<script type="text/javascript" src="${basePath}/static/publics/assets/jquery/jquery.min.js"></script>
<script type="text/javascript" src="${basePath}/static/publics/assets/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="${basePath}/static/publics/assets/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${basePath}/static/publics/assets/jqPaginator/jqPaginator.js"></script>
<script type="text/javascript">

function queryQua(pageNum,pageSize){
    var onlyId=$("#onlyId").val();
	var mrId=$("#mrId").val();
	var name=$("#name").val();
	var idCard=$("#idCard").val();
	var outHospitalOfficeId=$("#outHospitalOfficeId").val();
	var outHospitalStartTime=$("#outHospitalStartTime").val();
	var outHospitalEndTime=$("#outHospitalEndTime").val();
	var outHospitalTypeIds=[];
	$.each($("input[name='outHospitalTypeIds']"),function(i,item){
		if($(item).prop("checked")){
			outHospitalTypeIds[outHospitalTypeIds.length]=$(item).val();
		}
	})
	
	//alert(outHospitalStartTime+"--"+outHospitalEndTime);
	
	outHospitalTypeIds=outHospitalTypeIds.toString(",");
	//console.log(outHospitalTypeIds)
	if((outHospitalTypeIds==null || outHospitalTypeIds=="")&&(outHospitalOfficeId==null || outHospitalOfficeId=="") &&(mrId==null || mrId=="") &&(onlyId==null || onlyId=="") &&(outHospitalStartTime==null || outHospitalStartTime=="") && (outHospitalEndTime==null || outHospitalEndTime=='') && (name==null || name=='') && (idCard==null || idCard=='')){
		layer.alert("请输入查询条件!",{icon:7});
		return;
	}
	
    $.ajax({
		type:"post",
		url:"${basePath}/medrecord/getMedRecordList",
		data:{idCard:idCard,name:name,onlyId:onlyId,mrId:mrId,outHospitalOfficeId:outHospitalOfficeId,outHospitalStartTime:outHospitalStartTime,outHospitalEndTime:outHospitalEndTime,outHospitalTypeIds:outHospitalTypeIds,currentPage:pageNum,pageSize:pageSize},
		beforeSend:function(){
			$("#tbody").html("");
			$("#loading").show();
		}, 
		success:function(data){
			// console.log(data) 
			 $("#loading").hide(); 
			if(data.success){
				var dataList=data.data.medRecordList;
				var Count=data.data.totalCount;
				if(dataList.length>0){
					var html="";
					
				    for(var i=0;i<dataList.length;i++){
				    	var mrId=dataList[i].mrId?dataList[i].mrId:"";
					    var idCard=dataList[i].idCard?dataList[i].idCard:"";
					    var name=dataList[i].name?dataList[i].name:"";
					    var outHospitalDate=dataList[i].outHospitalDate?dataList[i].outHospitalDate:"";
					    var outOfficeName=dataList[i].outOfficeName?dataList[i].outOfficeName:"";
					    var outHospitalTypeName=dataList[i].outHospitalTypeName?dataList[i].outHospitalTypeName:"";
					    
						html+=" <tr data-guid="+dataList[i].firstGuid+">"+
				              "      <td class='tdLabel_5'>"+name+"</td>"+
				              "      <td class='tdLabel_5'>"+idCard+"</td>"+
				              "      <td class='tdLabel_5'>"+mrId+"</td>"+
				              "      <td class='tdLabel_5'>"+outHospitalDate+"</td>"+
				              "      <td class='tdLabel_5'>"+outOfficeName+"</td>"+
				              "      <td class='tdLabel_5'>"+outHospitalTypeName+"</td>"+
				              
				              "      <td class='tdLabel_5'><a class='int' style='padding:0px 5px 3px' onclick='upload(event)'>上传文件</a>"+
			                  
			                  "      </td>"+
				              "  </tr>";
					}
					
					$("#tbody").html(html);
					page(pageNum,Count,pageSize);
				}else{
					$("#tbody").html("");
					layer.alert("查询的数据为空！",{icon:5});
				    $("#currentPage").html("0/0");
					$("#totalPage").html("0");
					$("#page_plus").html("");	

               }
			}else{
				layer.alert(data.msg,{icon:5});
				$("#tbody").html("");
				$("#currentPage").html("0/0");
				$("#totalPage").html("0");
				$("#page_plus").html("");	
			} 
		}
	}) 
	
}

 function page(currentPage,totalCounts,pageSize){
	   /*  var pageSize=1; */
        var visiblePages = 10;
        var totalPages = Math.ceil(totalCounts/pageSize);
        $('#page_plus').jqPaginator({
            totalCounts: totalCounts,
            pageSize:pageSize,
            visiblePages: visiblePages,
            currentPage: currentPage,

            first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
            prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
            next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
            last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
            page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
            onPageChange: function (num,type) {
          
            	 if(type !='init'){
                 
            		 queryQua(num,pageSize);
                 }
            	
                $("#totalPage").html(totalCounts);
                $("#currentPage").html(num+"/"+totalPages);
            }
        });

    }
 
	 function selectAll(){
		  $('input[name="outHospitalTypeIds"]').each(function(){  
	          //此处如果用attr，会出现第三次失效的情况  
	          $(this).prop("checked",true);  
	      });  
	}

	function disableAll(){
		  $('input[name="outHospitalTypeIds"]').each(function(){  
	          //此处如果用attr，会出现第三次失效的情况  
	          $(this).prop("checked",false);  
	      });  
	}
	
	//查看按钮事件
	 function upload(event){
		 var eve = event || window.event; //获取事件对象
		 var objEle = eve.target || eve.srcElement; 
		 var target=$(objEle);
		 var guid=target.closest("tr").attr("data-guid");
		 window.open('${basePath}/medrecord/manageMedrecordImage?firstGuid='+guid);
		 //window.location.href='${basePath}/medrecord/uploadFile?firstGuid='+guid;
	 }
</script>
